﻿var pageNo=1;
var pageTotal=1;
$(function(){
    //图片单选按钮点击事件
    $(".myrdo:radio").css("cursor","pointer");
    $(".myrdo:radio").click(function(){
        myrdo($(this));
    });
    $(".radio-text").css("cursor","pointer");
    $(".radio-text").click(function(){
        // alert($(this).prev().val());
        $(".myrdo:radio").prop("checked",false);
        $(this).prev().prop("checked",true);
        myrdo($(this).prev());
    });

});
//图片单选按钮点击事件
function myrdo($this) {
    var type=$this.val();
    var url="/picture/pictureListajax?classify=" + type;
    $.post(url,function(result){
        if(result.pictureList.length!=0){
            var sttable = "";
            for (var i = 0; i < result.pictureList.length; i++) {
                sttable += "<tr>";
                sttable += "<td width='25px'>";
                sttable += "<label><input type=\"checkbox\" class=\"ace\" ><span class=\"lbl\"></span></label>";
                sttable += "</td>";
                sttable += "<td width='80px'>";
                sttable += result.pictureList[i].id;
                sttable += "</td>";
                sttable += "<td width='100px'>";
                sttable += result.pictureList[i].classify;
                sttable += "</td>";
                sttable += "<td width='220px'><img src='"+result.pictureList[i].images+"'/>";
                sttable += "</td>";
                sttable += "<td width='250px'>";
                sttable += result.pictureList[i].imagesName;
                sttable += "</td>";
                sttable += "<td width='250px'><a target=\"_blank\" href='";
                sttable += result.pictureList[i].href;
                sttable += "'>"+result.pictureList[i].href+"</a></td>";
                sttable += "<td  class=\"td-manage\">";
                sttable += " <a title=\"编辑\" onclick=\"member_edit('编辑','member-add.html','4','','510')\" href=\"javascript:;\"  class=\"btn btn-xs btn-info\" ><i class=\"icon-edit bigger-120\"></i></a>";
                sttable += " <a title=\"删除\" href=\"javascript:;\"  onclick=\"member_del(this,'1')\" class=\"btn btn-xs btn-warning\" ><i class=\"icon-trash  bigger-120\"></i></a>";
                sttable += "</td>";
                sttable += "</tr>";
            }
            $("#sertbody").html(sttable);
            pageNo = result.pageNo;
            pageTotal = result.pageTotal;
            var sttable2 = "";
            if (pageNo != pageTotal) {
                sttable2 += "<tr><td colspan='7' class='text-center'>";
                sttable2 += " <a id='downye' href='javascript:void(0);' onclick='downye();' name='down' value='下一页' style='cursor: pointer;'>下一页</a>";
                sttable2 += " <a id='meiye' href='javascript:void(0);' onclick='meiye();' style='cursor: pointer;'>尾页</a>";
                sttable2 += "</td></tr>";
            }
            $("#sertfoot").html(sttable2);
        } else {
            alert("没有数据！");
        }
    },"json");
    jj();
};

//搜索按钮点击事件
/*
function subbut() {
    var type = $(".myrdo:checked").val();
    var url="/picture/pictureListajax?classify=" + type;
    $.post(url, function (result) {
        if(result.officialTypeList.length!=0){
            var sttable = "";
            for (var i = 0; i < result.officialTypeList.length; i++) {
                sttable += "<tr>";
                sttable += "<td width='25px'>";
                sttable += "<label><input type=\"checkbox\" class=\"ace\" ><span class=\"lbl\"></span></label>";
                sttable += "</td>";
                sttable += "<td width='80px'>";
                sttable += result.officialTypeList[i].id;
                sttable += "</td>";
                sttable += "<td width='100px'>";
                sttable += result.officialTypeList[i].type;
                sttable += "</td>";
                sttable += "<td width='100px'>";
                sttable += result.officialTypeList[i].title;
                sttable += "</td>";
                sttable += "<td width='150px'>";
                sttable += result.officialTypeList[i].content;
                sttable += "</td>";
                sttable += "<td width='150px'><a target=\"_blank\" href='";
                sttable += result.officialTypeList[i].contentlink;
                sttable += "'>"+result.officialTypeList[i].contentlink+"</a></td>";
                sttable += "<td  class=\"td-manage\">";
                sttable += " <a title=\"编辑\" onclick=\"member_edit('编辑','member-add.html','4','','510')\" href=\"javascript:;\"  class=\"btn btn-xs btn-info\" ><i class=\"icon-edit bigger-120\"></i></a>";
                sttable += " <a title=\"删除\" href=\"javascript:;\"  onclick=\"member_del(this,'1')\" class=\"btn btn-xs btn-warning\" ><i class=\"icon-trash  bigger-120\"></i></a>";
                sttable += "</td>";
                sttable += "</tr>";
            }
            $("#sertbody").html(sttable);
            pageNo = result.pageNo;
            pageTotal = result.pageTotal;
            var sttable2 = "";
            if (pageNo != pageTotal) {
                sttable2 += "<tr><td colspan='10' class='text-center'>";
                sttable2 += " <a id='downye' href='javascript:void(0);' onclick='downye();' name='down' value='下一页' style='cursor: pointer;'>下一页</a>";
                sttable2 += " <a id='meiye' href='javascript:void(0);' onclick='meiye();' style='cursor: pointer;'>尾页</a>";
                sttable2 += "</td></tr>";
            }
            $("#sertfoot").html(sttable2);
        } else {
            alert("没有数据！");
        }
    }, "json");
    jj();
};
*/

//为动态添加的元素重新绑定事件
function jj() {
    $("#suoye").on("click", "suoye();");
    $("#upye").on("click", "upye();");
    $("#downye").on("click", "downye();");
    $("#meiye").on("click", "meiye();");
}

//首页点击事件
function suoye() {
    var type = $(".myrdo:checked").val();
    var url="/picture/pictureListajax?pageNo=1&classify=" + type;
    $.post(url, function (result) {
        if(result.pictureList.length!=0){
            var sttable = "";
            for (var i = 0; i < result.pictureList.length; i++) {
                sttable += "<tr>";
                sttable += "<td width='25px'>";
                sttable += "<label><input type=\"checkbox\" class=\"ace\" ><span class=\"lbl\"></span></label>";
                sttable += "</td>";
                sttable += "<td width='80px'>";
                sttable += result.pictureList[i].id;
                sttable += "</td>";
                sttable += "<td width='100px'>";
                sttable += result.pictureList[i].classify;
                sttable += "</td>";
                sttable += "<td width='220px'><img src='"+result.pictureList[i].images+"'/>";
                sttable += "</td>";
                sttable += "<td width='250px'>";
                sttable += result.pictureList[i].imagesName;
                sttable += "</td>";
                sttable += "<td width='250px'><a target=\"_blank\" href='";
                sttable += result.pictureList[i].href;
                sttable += "'>"+result.pictureList[i].href+"</a></td>";
                sttable += "<td  class=\"td-manage\">";
                sttable += " <a title=\"编辑\" onclick=\"member_edit('编辑','member-add.html','4','','510')\" href=\"javascript:;\"  class=\"btn btn-xs btn-info\" ><i class=\"icon-edit bigger-120\"></i></a>";
                sttable += " <a title=\"删除\" href=\"javascript:;\"  onclick=\"member_del(this,'1')\" class=\"btn btn-xs btn-warning\" ><i class=\"icon-trash  bigger-120\"></i></a>";
                sttable += "</td>";
                sttable += "</tr>";
            }
            $("#sertbody").html(sttable);
            pageNo = result.pageNo;
            pageTotal = result.pageTotal;
            var sttable2 = "";
            sttable2 += "<tr><td colspan='10' class='text-center'>";
            sttable2 += " <a id='downye' href='javascript:void(0);' onclick='downye();' name='down' value='下一页' style='cursor: pointer;'>下一页</a>";
            sttable2 += " <a id='meiye' href='javascript:void(0);' onclick='meiye();' style='cursor: pointer;'>尾页</a>";
            sttable2 += "</td></tr>";
            $("#sertfoot").html(sttable2);
        } else {
            alert("没有数据！");
        }
    }, "json");
    jj();
};

//上一页点击事件
function upye() {
    var type = $(".myrdo:checked").val();
    var url="/picture/pictureListajax?pageNo=" + (pageNo - 1) +"&classify=" + type;
    $.post(url, function (result) {
        if(result.pictureList.length!=0){
            var sttable = "";
            for (var i = 0; i < result.pictureList.length; i++) {
                sttable += "<tr>";
                sttable += "<td width='25px'>";
                sttable += "<label><input type=\"checkbox\" class=\"ace\" ><span class=\"lbl\"></span></label>";
                sttable += "</td>";
                sttable += "<td width='80px'>";
                sttable += result.pictureList[i].id;
                sttable += "</td>";
                sttable += "<td width='100px'>";
                sttable += result.pictureList[i].classify;
                sttable += "</td>";
                sttable += "<td width='220px'><img src='"+result.pictureList[i].images+"'/>";
                sttable += "</td>";
                sttable += "<td width='250px'>";
                sttable += result.pictureList[i].imagesName;
                sttable += "</td>";
                sttable += "<td width='250px'><a target=\"_blank\" href='";
                sttable += result.pictureList[i].href;
                sttable += "'>"+result.pictureList[i].href+"</a></td>";
                sttable += "<td  class=\"td-manage\">";
                sttable += " <a title=\"编辑\" onclick=\"member_edit('编辑','member-add.html','4','','510')\" href=\"javascript:;\"  class=\"btn btn-xs btn-info\" ><i class=\"icon-edit bigger-120\"></i></a>";
                sttable += " <a title=\"删除\" href=\"javascript:;\"  onclick=\"member_del(this,'1')\" class=\"btn btn-xs btn-warning\" ><i class=\"icon-trash  bigger-120\"></i></a>";
                sttable += "</td>";
                sttable += "</tr>";
            }
            $("#sertbody").html(sttable);
            var sttable2 = "";
            sttable2 += "<tr><td colspan='10' class='text-center'>";
            pageNo = result.pageNo;
            pageTotal = result.pageTotal;
            if (pageNo != 1) {
                sttable2 += " <a id='suoye' href='javascript:void(0);' onclick='suoye();' style='cursor: pointer;'>首页</a>";
                sttable2 += " <a id='upye' href='javascript:void(0);' onclick='upye();' style='cursor: pointer;'>上一页</a>";
            }
            sttable2 += " <a id='downye' href='javascript:void(0);' onclick='downye();' name='down' value='下一页' style='cursor: pointer;'>下一页</a>";
            sttable2 += " <a id='meiye' href='javascript:void(0);' onclick='meiye();' style='cursor: pointer;'>尾页</a>";
            sttable2 += "</td></tr>";
            $("#sertfoot").html(sttable2);
        } else {
            alert("没有数据！");
        }
    }, "json");
    jj();
};

//下一页点击事件
function downye() {
    var type = $(".myrdo:checked").val();
    var url="/picture/pictureListajax?pageNo=" + (pageNo + 1) +"&classify=" + type;
    $.post(url, function (result) {

        if(result.pictureList.length!=0){
            var sttable = "";
            for (var i = 0; i < result.pictureList.length; i++) {
                sttable += "<tr>";
                sttable += "<td width='25px'>";
                sttable += "<label><input type=\"checkbox\" class=\"ace\" ><span class=\"lbl\"></span></label>";
                sttable += "</td>";
                sttable += "<td width='80px'>";
                sttable += result.pictureList[i].id;
                sttable += "</td>";
                sttable += "<td width='100px'>";
                sttable += result.pictureList[i].classify;
                sttable += "</td>";
                sttable += "<td width='220px'><img src='"+result.pictureList[i].images+"'/>";
                sttable += "</td>";
                sttable += "<td width='250px'>";
                sttable += result.pictureList[i].imagesName;
                sttable += "</td>";
                sttable += "<td width='250px'><a target=\"_blank\" href='";
                sttable += result.pictureList[i].href;
                sttable += "'>"+result.pictureList[i].href+"</a></td>";
                sttable += "<td  class=\"td-manage\">";
                sttable += " <a title=\"编辑\" onclick=\"member_edit('编辑','member-add.html','4','','510')\" href=\"javascript:;\"  class=\"btn btn-xs btn-info\" ><i class=\"icon-edit bigger-120\"></i></a>";
                sttable += " <a title=\"删除\" href=\"javascript:;\"  onclick=\"member_del(this,'1')\" class=\"btn btn-xs btn-warning\" ><i class=\"icon-trash  bigger-120\"></i></a>";
                sttable += "</td>";
                sttable += "</tr>";
            }
            $("#sertbody").html(sttable);
            var sttable2 = "";
            sttable2 += "<tr><td colspan='10' class='text-center'>";
            sttable2 += " <a id='suoye' href='javascript:void(0);' onclick='suoye();' style='cursor: pointer;'>首页</a>";
            sttable2 += " <a id='upye' href='javascript:void(0);' onclick='upye();' style='cursor: pointer;'>上一页</a>";
            pageNo = result.pageNo;
            pageTotal = result.pageTotal;
            if (pageNo != pageTotal) {
                sttable2 += " <a id='downye' href='javascript:void(0);' onclick='downye();' name='down' value='下一页' style='cursor: pointer;'>下一页</a>";
                sttable2 += " <a id='meiye' href='javascript:void(0);' onclick='meiye();' style='cursor: pointer;'>尾页</a>";
            }
            sttable2 += "</td></tr>";
            $("#sertfoot").html(sttable2);
        } else {
            alert("没有数据！");
        }
    }, "json");
    jj();
}

//尾页点击事件
function meiye() {
    var type = $(".myrdo:checked").val();
    var url="/picture/pictureListajax?pageNo=" + pageTotal +"&classify=" + type;
    $.post(url, function (result1) {
        pageTotal = result1.pageTotal;
        var url="/picture/pictureListajax?pageNo=" + pageTotal +"&classify=" + type;
        $.post(url, function (result) {

            if(result.pictureList.length!=0){
                var sttable = "";
                for (var i = 0; i < result.pictureList.length; i++) {
                    sttable += "<tr>";
                    sttable += "<td width='25px'>";
                    sttable += "<label><input type=\"checkbox\" class=\"ace\" ><span class=\"lbl\"></span></label>";
                    sttable += "</td>";
                    sttable += "<td width='80px'>";
                    sttable += result.pictureList[i].id;
                    sttable += "</td>";
                    sttable += "<td width='100px'>";
                    sttable += result.pictureList[i].classify;
                    sttable += "</td>";
                    sttable += "<td width='220px'><img src='"+result.pictureList[i].images+"'/>";
                    sttable += "</td>";
                    sttable += "<td width='250px'>";
                    sttable += result.pictureList[i].imagesName;
                    sttable += "</td>";
                    sttable += "<td width='250px'><a target=\"_blank\" href='";
                    sttable += result.pictureList[i].href;
                    sttable += "'>"+result.pictureList[i].href+"</a></td>";
                    sttable += "<td  class=\"td-manage\">";
                    sttable += " <a title=\"编辑\" onclick=\"member_edit('编辑','member-add.html','4','','510')\" href=\"javascript:;\"  class=\"btn btn-xs btn-info\" ><i class=\"icon-edit bigger-120\"></i></a>";
                    sttable += " <a title=\"删除\" href=\"javascript:;\"  onclick=\"member_del(this,'1')\" class=\"btn btn-xs btn-warning\" ><i class=\"icon-trash  bigger-120\"></i></a>";
                    sttable += "</td>";
                    sttable += "</tr>";
                }
                $("#sertbody").html(sttable);
                pageNo = result.pageNo;
                pageTotal = result.pageTotal;
                var sttable2 = "";
                sttable2 += "<tr><td colspan='10' class='text-center'>";
                sttable2 += " <a id='suoye' href='javascript:void(0);' onclick='suoye();' style='cursor: pointer;'>首页</a>";
                sttable2 += " <a id='upye' href='javascript:void(0);' onclick='upye();' style='cursor: pointer;'>上一页</a>";
                sttable2 += "</td></tr>";
                $("#sertfoot").html(sttable2);
            } else {
                alert("没有数据！");
            }
        }, "json");
    }, "json");
    jj();
};


